var Forget = function () {
    var handleForget = function () {
        $('.forget-form').validate({
            errorElement: 'span', //default input error message container
            errorClass: 'help-block', // default input error message class
            focusInvalid: false, // do not focus the last invalid input
            rules: {
                password: {
                    required: true
                },
                rpassword: {
                    required: true,
                    equalTo: "#register_password"
                }
            },

            messages: {
                password: {
                    required: "请输入新密码！"
                },
                rpassword: {
                    required: "请输入确认密码！",
                    equalTo: "密码不一致！"
                }
            },

            invalidHandler: function (event, validator) { //display error alert on form submit
                $('.alert-danger', $('.forget-form')).show();
            },

            highlight: function (element) { // hightlight error inputs
                $(element)
                    .closest('.form-group').addClass('has-error'); // set error class to the control group
            },

            success: function (label) {
                label.closest('.form-group').removeClass('has-error');
                label.remove();
            },

            errorPlacement: function (error, element) {
                error.insertAfter(element.closest('.input-icon'));
            },

            submitHandler: function (form) {
                form.submit(); // form validation success, call ajax form submit
            }
        });

        $('.forget-form input').keypress(function (e) {
            if (e.which == 13) {
                var login_form = $('.forget-form');
                if (login_form.validate().form()) {
                    login_form.submit(); //form validation success, call ajax form submit
                }
                return false;
            }
        });

        $("#register_password").bind("keydown", function (e) {
            if (e.which == 13) {
                e.preventDefault();
                $("#rpassword").focus();
            }
        });

        jQuery('#login-back-btn').click(function () {
            window.location.href = "index";
        });

    };

    return {
        //main function to initiate the module
        init: function () {
            handleForget();
            $.backstretch([
                "img/login/bg/02.jpg",
//                "img/login/bg/01.jpg",
//                "img/login/bg/03.jpg",
                "img/login/bg/04.jpg",
                "img/login/bg/05.jpg"
            ], {
                fade: 1000,
                duration: 5000
            });
        }

    };

}();